//
//  MinecraftViewController.m
//  CommunitySupermarketProiect
//
//  Created by 吕惠卿 on 2017/9/25.
//  Copyright © 2017年 吕惠卿. All rights reserved.
//

#import "MinecraftViewController.h"

@interface MinecraftViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UINavigationControllerDelegate>
@property (nonatomic, strong)UICollectionView *collectionView;
//@property (nonatomic, strong)NSMutableArray *fiveImageMutabArray;
//@property (nonatomic, strong)NSMutableArray *fiveNameMutabArray;
@property (nonatomic, strong)NSArray *fiveImageMutabArray;
@property (nonatomic, strong)NSArray *fiveNameMutabArray;
@property (nonatomic, strong)NSArray *twoImgArr;
@property (nonatomic, strong)NSArray *twoNameArr;
@property (nonatomic, strong)NSArray *FourImgArr;
@property (nonatomic, strong)NSArray *FourNameArr;
@end

static NSString *MinecraCell = @"MinecraCell";
static NSString *grayCell = @"grayCell";
static NSString *minecTwoCell = @"minecTwoCell";
static NSString *orderCell = @"orderCell";
static NSString *fivecell = @"fivecell";
static NSString *sevenCell = @"sevenCell";



@implementation MinecraftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    WhiteColor;
    [self.view addSubview:self.collectionView];
    // 设置导航控制器的代理为self
    self.navigationController.delegate = self;
    
    
    self.fiveImageMutabArray = @[@"我的商城订单1",@"我的超市2",@"我的外卖3",@"我的预约订单4",@"我的退款售后5"];
    self.fiveNameMutabArray = @[@"商城订单",@"超市订单",@"外卖订单",@"预约订单",@"退款/售后"];
    self.twoImgArr = @[@"我的个人01",@"我的地址02"];
    self.twoNameArr = @[@"个人信息",@"收货地址"];
    self.FourImgArr = @[@"我-的账单03",@"我的评价04",@"我的账户安全05",@"我的分享06"];
    self.FourNameArr = @[@"我的账单",@"我的评价",@"账户安全",@"我的分享"];
}
//-(NSMutableArray *)fiveImageMutabArray{
//    if (!self.fiveImageMutabArray) {
//        self.fiveImageMutabArray = [[NSMutableArray alloc]init];
//    }
//    return self.fiveImageMutabArray;
//}
//-(NSMutableArray *)fiveNameMutabArray{
//    if (!self.fiveNameMutabArray) {
//        self.fiveNameMutabArray = [[NSMutableArray alloc]init];
//    }
//    return self.fiveNameMutabArray;
//}
#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}

#pragma mark -UICollectionViewDelegate
-(UICollectionView *)collectionView{
    if (_collectionView == nil) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, -20, WIDTH, HEIGHT) collectionViewLayout:flowLayout];
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        //设置代理
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        //背景颜色
        _collectionView.backgroundColor = [UIColor whiteColor];
        //自适应大小
        _collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        
        [_collectionView registerClass:[MinecraftViewHeaderCollectionViewCell class] forCellWithReuseIdentifier:@"MinecraCell"];
        [_collectionView registerClass:[LineGrayCollectionViewCell class] forCellWithReuseIdentifier:@"grayCell"];
        [_collectionView registerClass:[MinecraftViewTwoCollectionViewCell class] forCellWithReuseIdentifier:@"minecTwoCell"];
        
        [_collectionView registerClass:[MyOrderCollectionViewCell class] forCellWithReuseIdentifier:@"orderCell"];
        [_collectionView registerClass:[MyFiveCollectionViewCell class] forCellWithReuseIdentifier:@"fivecell"];
        [_collectionView registerClass:[MySevenCollectionViewCell class] forCellWithReuseIdentifier:@"sevenCell"];
    }
    return _collectionView;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {//头像
        MinecraftViewHeaderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MinecraCell forIndexPath:indexPath];
        return cell;
    }
    else if (indexPath.section == 1){//三个分区、收藏夹、关注店铺、优惠券
        MinecraftViewTwoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:minecTwoCell forIndexPath:indexPath];
        if (indexPath.item == 0) {
            cell.numLab.text = @"1";
            cell.nameLab.text = @"收藏夹";
        }
        else if (indexPath.item == 1){
            cell.numLab.text = @"1";
            cell.nameLab.text = @"关注店铺";
        }
        else{
            cell.numLab.text = @"1";
            cell.nameLab.text = @"优惠券";
        }
        return cell;
    }
    else if (indexPath.section == 2){
        LineGrayCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:grayCell forIndexPath:indexPath];
        return cell;
    }
    else if (indexPath.section == 3){
        MyOrderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:orderCell forIndexPath:indexPath];
//        cell.backgroundColor = [UIColor redColor];
        return cell;
    }
    else if (indexPath.section == 4){
        MyFiveCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:fivecell forIndexPath:indexPath];
        cell.img.image = [[UIImage imageNamed:_fiveImageMutabArray[indexPath.item]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        cell.lab.text = [NSString stringWithFormat:@"%@",_fiveNameMutabArray[indexPath.item]];
        return cell;
    }
    else if (indexPath.section == 5){
        LineGrayCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:grayCell forIndexPath:indexPath];
        return cell;
    }
    else if (indexPath.section == 6){
        MySevenCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:sevenCell forIndexPath:indexPath];
        cell.leftImg.image = [[UIImage imageNamed:_twoImgArr[indexPath.item]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        cell.nameLab.text = [NSString stringWithFormat:@"%@",_twoNameArr[indexPath.item]];
        
        return cell;
    }
    else if (indexPath.section == 7){
        LineGrayCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:grayCell forIndexPath:indexPath];
        return cell;
    }
    else{
        MySevenCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:sevenCell forIndexPath:indexPath];
        cell.leftImg.image = [[UIImage imageNamed:_FourImgArr[indexPath.item]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        cell.nameLab.text = [NSString stringWithFormat:@"%@",_FourNameArr[indexPath.item]];
        return cell;
    }

}
//定义展示的Section的个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 9;
}
//定义展示的UICollectionViewCell的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }
    else if (section == 1){
        return 3;
    }
    else if (section == 2){
        return 1;
    }
    else if (section == 3){
        return 1;
    }
    else if (section == 4){
        return 5;
    }
    else if (section == 5){
        return 1;
    }
    else if (section == 6){
        return 2;
    }
    else if (section == 7){
        return 1;
    }
    else{
        return 4;
    }
}

//机会选中消息
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return  YES;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return (CGSize){MCScreenSize.width , 180};
    }
    else if (indexPath.section == 1){
        return (CGSize){MCScreenSize.width/3 , 60};
    }
    else if (indexPath.section == 2){
        return (CGSize){MCScreenSize.width , 5};
    }
    else if (indexPath.section == 3){
        return (CGSize){MCScreenSize.width , 45};
    }
    else if (indexPath.section == 4){
        return (CGSize){MCScreenSize.width/5 , 68};
    }
    else if (indexPath.section == 5){
        return (CGSize){MCScreenSize.width , 5};
    }
    else if (indexPath.section == 6){
        return (CGSize){MCScreenSize.width , 45};
    }
    else if (indexPath.section == 7){
        return (CGSize){MCScreenSize.width , 5};
    }
    else{
        return (CGSize){MCScreenSize.width , 45};
    }
    
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
